package iterator;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class BookList {
    private List<Book> bookList;
    private int index;
    private Iterator iterator;

    public BookList() {
        this.bookList = new ArrayList<>();
    }

    public void addBook(Book book) {
        bookList.add(book);
    }

    public void deleteBook(Book book) {
        int bookIndex = bookList.indexOf(book);
        bookList.remove(bookIndex);
    }

    public boolean hasNext() {
        if (index >= bookList.size()) {
            return false;
        }
        return true;
    }

    public Book getNext(){
        return bookList.get(index++);
    }

    public Iterator iterator(){
        return new Iter();
    }

    class Iter implements Iterator{

        @Override
        public boolean hasNext() {
            if (index >= bookList.size()) {
                return false;
            }
            return true;
        }

        @Override
        public Object next() {
            return bookList.get(index++);
        }
    }
}
